home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Demo / pdist / makechangelog.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  2.9 KB  |  110 lines

  1. #! /usr/bin/env python
  2.  
  3. """Turn a pile of RCS log output into ChangeLog file entries.
  4.  
  5. """
  6.  
  7. import sys
  8. import string
  9. import regex
  10. import getopt
  11. import time
  12.  
  13. def main():
  14.     args = sys.argv[1:]
  15.     opts, args = getopt.getopt(args, 'p:')
  16.     prefix = ''
  17.     for o, a in opts:
  18.         if p == '-p': prefix = a
  19.  
  20.     f = sys.stdin
  21.     allrevs = []
  22.     while 1:
  23.         file = getnextfile(f)
  24.         if not file: break
  25.         revs = []
  26.         while 1:
  27.             rev = getnextrev(f, file)
  28.             if not rev:
  29.                 break
  30.             revs.append(rev)
  31.         if revs:
  32.             allrevs[len(allrevs):] = revs
  33.     allrevs.sort()
  34.     allrevs.reverse()
  35.     for rev in allrevs:
  36.         formatrev(rev, prefix)
  37.  
  38. parsedateprog = regex.compile(
  39.     '^date: \([0-9]+\)/\([0-9]+\)/\([0-9]+\) ' +
  40.     '\([0-9]+\):\([0-9]+\):\([0-9]+\);  author: \([^ ;]+\)')
  41.  
  42. authormap = {
  43.     'guido': 'Guido van Rossum  <guido@cnri.reston.va.us>',
  44.     'jack': 'Jack Jansen  <jack@cwi.nl>',
  45.     'sjoerd': 'Sjoerd Mullender  <sjoerd@cwi.nl>',
  46.     }
  47.  
  48. def formatrev(rev, prefix):
  49.     dateline, file, revline, log = rev
  50.     if parsedateprog.match(dateline) >= 0:
  51.         fields = parsedateprog.group(1, 2, 3, 4, 5, 6)
  52.         author = parsedateprog.group(7)
  53.         if authormap.has_key(author): author = authormap[author]
  54.         tfields = map(string.atoi, fields) + [0, 0, 0]
  55.         tfields[5] = tfields[5] - time.timezone
  56.         t = time.mktime(tuple(tfields))
  57.         print time.ctime(t), '', author
  58.         words = string.split(log)
  59.         words[:0] = ['*', prefix + file + ':']
  60.         maxcol = 72-8
  61.         col = maxcol
  62.         for word in words:
  63.             if col > 0 and col + len(word) >= maxcol:
  64.                 print
  65.                 print '\t' + word,
  66.                 col = -1
  67.             else:
  68.                 print word,
  69.             col = col + 1 + len(word)
  70.         print
  71.         print
  72.  
  73. startprog = regex.compile("^Working file: \(.*\)$")
  74.  
  75. def getnextfile(f):
  76.     while 1:
  77.         line = f.readline()
  78.         if not line: return None
  79.         if startprog.match(line) >= 0:
  80.             file = startprog.group(1)
  81.             # Skip until first revision
  82.             while 1:
  83.                 line = f.readline()
  84.                 if not line: return None
  85.                 if line[:10] == '='*10: return None
  86.                 if line[:10] == '-'*10: break
  87. ##              print "Skipped", line,
  88.             return file
  89. ##      else:
  90. ##          print "Ignored", line,
  91.  
  92. def getnextrev(f, file):
  93.     # This is called when we are positioned just after a '---' separator
  94.     revline = f.readline()
  95.     dateline = f.readline()
  96.     log = ''
  97.     while 1:
  98.         line = f.readline()
  99.         if not line: break
  100.         if line[:10] == '='*10:
  101.             # Ignore the *last* log entry for each file since it
  102.             # is the revision since which we are logging.
  103.             return None
  104.         if line[:10] == '-'*10: break
  105.         log = log + line
  106.     return dateline, file, revline, log
  107.  
  108. if __name__ == '__main__':
  109.     main()
  110.